package cn.android.support.v7.lib.sin.crown.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.InputType;
import android.util.AttributeSet;

import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2018/1/15.
 */

public class BinInputEditText extends android.support.v7.widget.AppCompatEditText {

    private Paint mPaint;
    private int lineColor = Color.parseColor("#B5B5B7");
    int strokeWidth = ProportionUtils.getInstance().adapterInt(3);//底线的高度

    //设置底线的颜色
    public void setLineColor(int lineColor) {
        this.lineColor = lineColor;
        invalidate();
    }

    //设置底线的高
    public void setStrokeWidth(int strokeWidth) {
        this.strokeWidth = strokeWidth;
        invalidate();
    }

    public BinInputEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(strokeWidth);
        // 你可以根据自己的具体需要在此处对画笔做更多个性化设置
        mPaint.setColor(lineColor);//底线的颜色

    }

    //注意 android:background="@null" 一定要是设置成null，以免样式出错。

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 画底线
        canvas.drawLine(0, this.getHeight() - strokeWidth, this.getWidth() - strokeWidth, this.getHeight() - strokeWidth, mPaint);
    }

    //是否禁止输入，true禁止，false不禁止
    public void BinInput(boolean b) {
        if (b) {
            //禁止输入，直接响应点击事件，手动输入无效。
            setInputType(InputType.TYPE_NULL);////禁止软键盘
            setFocusable(false);
        } else {
            setInputType(InputType.TYPE_CLASS_TEXT);//开启软键盘
            setFocusable(true);
        }
    }

}
